﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Bling.DSL;
using Bling.WPF;
using Bling.WPF.Custom;
using Bling.Core;

using Bling.Graphics;
using Bling.Util;
using Bling.Reactive;
using Bling.Angles;

namespace Bling.Tutorial {
  public class CustomLayout : Canvas {
    public CustomLayout() {
      CanvasBl Self = this;

      var Center = Self.CenterSize;

      int N = 10;
      var slider = new SliderBl(Self) { 
       Width = { Bind = Self.Width }, LeftTop = 0,
       Minimum = 0, Maximum = 2d.PI().Value,
      };
      var slider0 = this.Property(0d.Bl()); // slider.Value;
      RadianBl startAngle = slider0.Radians;
      var angle = startAngle;
      var sz = Self.Size.Min();
      var button = new ButtonBl[N];
      for (int i = 0; i < N; i++) {
        var label = "Button Number " + (i + 1);
        button[i] = new ButtonBl(Self) {
          Content = label,
        };
        var radius = sz - 2 * button[i].Width;
        radius = radius / 2d;
        button[i].CenterPosition = Center + angle.ToPoint * radius; 
        button[i].RenderTransform.Rotate = angle.Degrees;
        angle += 2.PI() / ((DoubleBl)N);
      }
      slider0[slider.Mouse.Enter].Stop(false);
      slider0[button[0].Click1].Animate().Duration(TimeSpan.FromSeconds(10)).Tween(d => d.Ease.Circ.InOut).AutoReverse(). //Forever().
        //StopOnCompleted(false).
        To = 2d.PI().Value;
      /*
      button[0].Click = () => {
        //slider0.Stop(true);
        //slider0.Now = 0;
        slider0.Animate().Duration(TimeSpan.FromSeconds(100)).Tween(d => d.Ease.Circ.InOut).AutoReverse(). //Forever().
          //StopOnCompleted(false).
          To = 2d.PI().Value;
      };
      */
    }
  }
}